package service

import (
	"fmt"
	"rongyy/src/models"
)

type AdminService struct {
	d *models.AdminModel
}

func (ds *AdminService) SignIn(req *models.AdminModel) (*models.AdminModel, error) {
	staff, err := req.SignIn()
	if err != nil {
		return nil, err
	}
	return staff, nil
}

func (ds *AdminService) Query(limit int, offset int) ([]models.AdminModel, int64, error) {
	am := &models.AdminModel{}
	admins, total, err := am.Query(limit, offset)
	if err != nil {
		return nil, 0, err
	}
	return admins, total, nil
}

func (ds *AdminService) Add(req *models.AdminModel) error {
	_, has, err := req.FindByUsername(req.Username)
	if err != nil {
		return err
	}
	if has {
		return fmt.Errorf("用户名已存在")
	}
	err = req.Insert()
	if err != nil {
		return err
	}
	return nil
}

func (as *AdminService) ChangePass(req *models.AdminPassReq) error {
	am := &models.AdminModel{}
	err := am.ChangePass(req)
	if err != nil {
		return err
	}
	return nil
}

//
//
//func (ds *DoctorService) Query(limit int, offset  int) ([]models.DoctorInfo, int64, error) {
//  dm  := &models.DoctorInfo{}
//  doctor,  total,  err := dm.Query(limit, offset)
//  if err != nil {
//    return nil,0, err
//  }
//  return doctor,total, nil
//}
//
//func (ds *DoctorService) Update(json *models.DoctorInfo) error {
//  err := json.Update()
//  if err != nil {
//    return err
//  }
//  return nil
//}
